package com.wt.admin.controller;

import com.wt.servicebase.websocket.server.WebSocketServer;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;


@Api(tags = "websocket通信类")
@RestController
@RequestMapping("/websocket")
@CrossOrigin
public class WebSocketController {

    @Autowired
    private WebSocketServer webSocketServer;

    /**
     * @Author dingchengxiang
     * @Description //TODO 测试websocket发送消息
     * @Date 14:41 2019/11/12
     * @Param []
     * @return java.lang.String
     **/
    @PostMapping("/sendAllWebSocket")
    public String test() {
        String text="你们好！这是websocket群体发送！";
        try {
            webSocketServer.sendInfo(text);
        }catch (IOException e){
            e.printStackTrace();
        }
        return text;
    }
}
